import numpy as np
import csv

def toInt(array):
	array=np.mat(array)
	m,n=np.shape(array)
	newarray=np.zeros((m,n))
	for i in range(m):
		for j in range(n):
			newarray[i][j]=int(array[i,j])
	return newarray

def nomalize(array):
	m,n=np.shape(array)
	for i in range(m):
		for j in range(n):
			if array[i][j]!=0:
				array[i][j]=1
	return array

def loadTrainData():
	l=[]
	with open('train.csv') as file:
		lines=csv.reader(file)
		for line in lines:
			l.append(line)
	l.remove(l[0])
	l=np.array(l)
	label=l[:,0]
	data=l[:,1:]
	return nomalize(toInt(data)),toInt(label)

def loadTestData():
	l=[]
	with open('test.csv') as file:
		lines=csv.reader(file)
		for line in lines:
			l.append(line)
	l.remove(l[0])
	l=np.array(l)
	
	data=l
	return nomalize(toInt(data))

def saveresult(res):
	with open('result.csv','w') as my_file:
		mywrite=csv.writer(my_file)
		for i in res:
			tmp=[]
			tmp.append(i)
			mywrite.writerow(tmp)




